//
//  CommendOrderViews.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/2/2.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "CommendOrderViews.h"
#import "MediaCollectionView.h"
#import "CommentStartView.h"
#import "LXSaveUserInforTool.h"
#import "MediaModel.h"
@interface CommendOrderViews()<UITextViewDelegate>
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic,strong) UIImageView *headerImgView;
@property (nonatomic, strong) CommentStartView *starView;
@property (nonatomic, strong) UITextView *cancellReTextView;
@property (nonatomic, strong) UILabel *placeHoder;
@property (nonatomic,strong) MediaCollectionView *mediaView;
@end
@implementation CommendOrderViews
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self viewConfig];
    }
    return self;
}
-(void)viewConfig
{
    self.frame = CGRectMake(0, 0, TSScreenWidth, TSScaleW(100));
    self.backgroundColor = kWhiteColor;
    [self addSubview:self.headerImgView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.starView];
    [self addSubview:self.cancellReTextView];
    [self.cancellReTextView addSubview:self.placeHoder];
    [self.cancellReTextView addSubview:self.mediaView];
    self.height = self.cancellReTextView.bottom + TSScaleW(10);
}
-(UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(10), TSScaleW(10), TSScaleW(47), TSScaleW(63))];
        _headerImgView.backgroundColor = kGrayTxtColor;
    }
    return _headerImgView;
}
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [TSWLTools allocLabel:@"初中数学运算大法" font:systemFont(TSScaleW(14)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(10) + _headerImgView.right, TSScaleW(10), TSScaleW(250), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _titleLabel;
}

-(CommentStartView *)starView{
    if (!_starView) {
        _starView = [[CommentStartView alloc]initWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom + TSScaleW(10), TSScaleW(80), TSScaleW(14))];
    }
    return _starView;
}
-(UITextView *)cancellReTextView
{
    if (!_cancellReTextView) {
        _cancellReTextView = [[UITextView alloc]initWithFrame:CGRectMake(TSScaleW(11), TSScaleW(34)+ _headerImgView.bottom, TSScreenWidth - TSScaleW(22), TSScaleW(207))];
        _cancellReTextView.backgroundColor = kMainBgColor;
        _cancellReTextView.delegate = self;
        _cancellReTextView.cornerRadius = TSScaleW(10);
        
    }
    return _cancellReTextView;
}
-(UILabel *)placeHoder{
    if (!_placeHoder) {
        _placeHoder = [TSWLTools allocLabel:@"为了下次更好的相遇，留下你的建议吧！！！" font:systemFont(TSScaleW(14)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(20), TSScaleW(20),_cancellReTextView.width - TSScaleW(20), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _placeHoder;
}


-(MediaCollectionView *)mediaView{
    if (!_mediaView) {
        _mediaView = [[MediaCollectionView alloc]initWithFrame:CGRectMake(TSScaleW(15),  _cancellReTextView.height - TSScaleW(60), TSScaleW(320), TSScaleW(50))];
        WS(weakSelf);
        _mediaView.limitCount = 5;
        _mediaView.row = 5;
        
        [LXSaveUserInforTool sharedUserTool].medaiType = 1;
        _mediaView.showCurrentIndexBlock = ^(NSInteger currentIndex) {
            //[weakSelf selectedIndex:currentIndex];
        };
        _mediaView.addCurrentBlock = ^{
           
        };
    }
    return _mediaView;
}



-(NSArray *)urlsArray{
    NSArray *arr = @[];
    if (!_mediaView.dataSource.count) {
        arr = @[];
    }else{
        NSMutableArray *array = [NSMutableArray array];
        for (MediaModel *model in _mediaView.dataSource) {
            if (model.imgUrl.length) {
                NSMutableString *string = [[NSMutableString alloc]initWithString:model.imgUrl];
                [array addObject:string];
            }
        }
        arr = array;
    }
    return arr;
}



- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSString *contentString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    
    if (contentString.length == 0) {
        self.placeHoder.hidden = NO;
    }else{
        self.placeHoder.hidden = YES;
    }
    return YES;
}
-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [_headerImgView sd_setImageWithURL:[NSURL URLWithString:_dataDic[@"gimage"]]];
    _titleLabel.text = _dataDic[@"gname"];
    
}
-(NSMutableDictionary *)requstDataDic
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:_dataDic[@"odid"] forKey:@"odid"];
    if (!_cancellReTextView.text.length) {
       
    }else{
        [dic setValue:_cancellReTextView.text forKey:@"content"];
    }
    NSString *star = [NSString stringWithFormat:@"%ld",_starView.commentStar];
    [dic setValue:star forKey:@"star"];
    if ([self urlsArray].count) {
        [dic setValue:[self urlsArray] forKey:@"images"];
    }
    
    return dic;
}
@end
